import java.util.Random;

public class ThreadDemo_数组求和2 {
    static int[] arr = new int[10000000];
    static int num1 = 0;
    static int num2 = 0;

    public static void main(String[] args) throws InterruptedException {
        Random random = new Random();
        for (int i = 0; i < arr.length; i++) {
            arr[i] = random.nextInt(100) + 1;
        }
        Thread t1 = new Thread(() -> {
            for (int i = 0; i < arr.length; i+=2) {
                num1 = num1 + arr[i];
            }
        });
        t1.start();

        Thread t2 = new Thread(() -> {
            for (int i = 1; i < arr.length; i+=2) {
                num2 = num2 + arr[i];
            }
        });

        t1.join();
        t2.join();
        System.out.println(num1 + num2);
    }
}
